package com.duanjw.springboot.springdoc.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.duanjw.springboot.springdoc.entity.User;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * @author duanjw
 */
@RestController
@RequestMapping("user")
@Tag(name = "用户接口")
public class UserController {

    /**
     * 查询所有用户
     *
     * @return
     */
    @GetMapping
    @Operation(summary = "查询所有用户")
    public List<User> userList() {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setId(i);
            user.setName("测试" + i);
            user.setBirthday(new Date());
            users.add(user);
        }
        return users;
    }

    /**
     * 条件查询用户
     *
     * @param id
     * @param name
     * @return
     */
    @GetMapping("conditions")
    @Operation(summary = "条件查询用户")
    public List<User> getByUsername(@Parameter(description = "用户id") @RequestParam Integer id, @Parameter(description = "用户姓名") @RequestParam(required = false) String name) {
        return new ArrayList<>();
    }

    /**
     * 新增用户
     *
     * @param user
     * @return
     */
    @PostMapping
    @Operation(summary = "新增用户")
    public boolean saveUser(@RequestBody User user) {
        return true;
    }

    /**
     * 删除用户
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除用户")
    public boolean deleteUser(@Parameter(description = "用户id") @PathVariable Integer id) {
        return true;
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @PutMapping
    @Operation(summary = "修改用户")
    public boolean deleteUser(@RequestBody User user) {
        return true;
    }
}
